class Xmlinfobif < ActiveRecord::Base
  # The header line lists the attribute names.  ID is quoted to work
  # around an issue with Excel and CSV files that start with "ID".
  def self.csv_header
    "Account,Amount,Description"
  end

  # Emit our attribute values as a line of CSVs
  def to_csv
    account << "," << amount.to_s << "," << description 
  end

  validates_presence_of :batch_id1, :interface, :voucher_type,:trans_type, :client, :account, :tax_code, :currency,:description
  validates_length_of :batch_id1, :maximum => 25
  validates_length_of :interface, :maximum => 25  
  validates_length_of :voucher_type, :maximum => 25
  validates_length_of :trans_type, :maximum => 2
  validates_length_of :client, :maximum => 25
  validates_length_of :account, :maximum => 25  
  validates_length_of :dim_1, :maximum => 25 
  validates_length_of :tax_code, :maximum => 25
  validates_length_of :tax_system, :maximum => 25  
  validates_length_of :currency, :maximum => 25  
  validates_length_of :description, :maximum => 255         
  validates_numericality_of :cur_amount,:amount
  validates_numericality_of :voucher_no,:only_integer => true, :allow_nil => false  
  validates_numericality_of :period ,:only_integer => true,  :allow_nil => false 
 # validates_format_of :voucher_date
   # :with => %r{\.(gif|jpg|png)$}i,
  #  :message => "must be a URL for a GIF, JPG, or PNG image"
 # validates_format_of :trans_date
  #  :with => %r{\.(gif|jpg|png)$}i,
   # :message => "must be a URL for a GIF, JPG, or PNG image"
protected
def validate
    errors.add(:voucher_no, "should be large than 0" ) if voucher_no.nil? || voucher_no < 0
    errors.add(:period, "should be large than 0" ) if period.nil? || period < 0
    #errors.add(:cur_amount, "should be at least 0.01" ) if cur_amount.nil? || cur_amount < 0.01
    #errors.add(:amount, "should be at least 0.01" ) if amount.nil? || amount < 0.01
    #errors.add(:cur_amount, " - Should be positive") if cur_amount.nil? || cur_amount < -0.01
    #errors.add(:amount, " - Should be positive") if amount.nil? || amount < -0.01
end
end
